package system

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type SysCompany struct {
	SysCompanyId     int64     `orm:"column(sys_company_id);pk"`
	UniqueCode       string    `description:"唯一编码"`
	CompanyName      string    `description:"公司名称"`
	CompanyShortName string    `description:"公司简称"`
	CreditCode       string    `description:"社会统一信用码"`
	Province         string    `description:"省"`
	City             string    `description:"市"`
	AreaTown         string    `description:"区"`
	CreateTime       time.Time `description:"创建时间"`
	ModifyTime       time.Time `description:"修改时间"`
}

type SysCompanyView struct {
	SysCompanyId     int64  `description:"公司ID"`
	UniqueCode       string `description:"唯一编码"`
	CompanyName      string `description:"公司名称"`
	CompanyShortName string `description:"公司简称"`
	CreditCode       string `description:"社会统一信用码"`
	Province         string `description:"省"`
	City             string `description:"市"`
	AreaTown         string `description:"区"`
	CreateTime       string `description:"创建时间"`
	ModifyTime       string `description:"修改时间"`
}

func (r *SysCompany) GetSysCompany() (item *SysCompanyView, err error) {
	o := orm.NewOrm()
	sql := `SELECT * FROM sys_company LIMIT 1`
	err = o.Raw(sql).QueryRow(&item)
	return
}

// 修改
func (m *SysCompany) Update(updateParams, whereParam map[string]interface{}) (err error) {
	to := orm.NewOrm()
	ptrStructOrTableName := "sys_company"

	qs := to.QueryTable(ptrStructOrTableName)
	for expr, exprV := range whereParam {
		qs = qs.Filter(expr, exprV)
	}
	_, err = qs.Update(updateParams)
	return
}
